home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 343_02 / fwrite.c < prev    next >
C/C++ Source or Header  |  1990-06-26  |  4KB  |  118 lines

  1.  
  2.  
  3.         /********************************************************
  4.         *
  5.         *       file c:\lsu\fwrite.c
  6.         *
  7.         *       Functions: This file contains
  8.         *           my_fwrite
  9.         *           my_fwriteln
  10.         *           tab_string
  11.         *
  12.         *       Purpose: These functions write a string to a
  13.         *                file.
  14.         *
  15.         *       Modifications:
  16.         *           3 September 1986 - created from the routines
  17.         *               in Jamsa's book on pp.  95-96.
  18.         *           12 June 1987 - ported to Borland Turbo C and
  19.         *               changed the names of functions from
  20.         *               fwrite and fwriteln to my_fwrite and
  21.         *               my_fwriteln. This is because Borland
  22.         *               defines their own functions with the
  23.         *               same names.
  24.         *
  25.         *********************************************************/
  26.  
  27. #include "d:\cips\cips.h"
  28.  
  29. /*
  30.  * NAME: my_fwrite (file_pointer, string)
  31.  *
  32.  * FUNCTION: Writes the string to the file specified by
  33.  *           file_pointer insuring that a carriage
  34.  *           return is not written.
  35.  *
  36.  * EXAMPLES fwrite (fp, last_name);
  37.  *
  38.  * VARIABLES USED: string: pointer to the string to be written.
  39.  *                 file_pointer: pointer to the output file.
  40.  *
  41.  * PSEUDO CODE: while (the letter referenced by *string is not an
  42.  *                     End of Line (EOL) or equal to NULL)
  43.  *
  44.  *                 write the letter to the file
  45.  *                 increment string to point to the next letter
  46.  *
  47.  *              return without printing a carriage return
  48.  *
  49.  */
  50.  
  51.  my_fwrite (file_pointer, string)
  52.   FILE *file_pointer;  /* requires stdio.h to be #included */
  53.   char *string;
  54.  {
  55.  
  56.   while (*string != '\n' && *string != '\0')
  57.     putc (*string++, file_pointer);
  58.  
  59.  }
  60.  
  61.  
  62. /*
  63.  * NAME: my_fwriteln (string)
  64.  *
  65.  * FUNCTION: Writes the string to the file referenced
  66.  *           by file_pointer insuring that only one
  67.  *           carriage is written.   If a line is read
  68.  *           from a file, we have no way of knowing whether
  69.  *           or not it contains a newline character.  If we
  70.  *           assume it does, and none are present the output
  71.  *           will consist of one long line.  If we assume it
  72.  *           doesn't and it does, each line is double spaced.
  73.  *
  74.  * EXAMPLES fwriteln (file_pointer, address);
  75.  *
  76.  * VARIABLES USED: string: pointer to the string to be written.
  77.  *                 file_pointer: pointer to the output file.
  78.  *
  79.  * PSEUDO CODE: while (letter referenced by *string is not an
  80.  *                     End of Line (EOL) or  equal to NULL)
  81.  *                 write the letter to the file
  82.  *                 increment string to point to the next letter
  83.  *
  84.  *              write a newline character to the file
  85.  *
  86.  */
  87.  
  88.  my_fwriteln (file_pointer, string)
  89.   char *string;
  90.   FILE *file_pointer;  /* requires stdio.h be #included */
  91.  {
  92.  
  93.   while (*string != '\n' && *string != '\0'){
  94.     putc (*string++, file_pointer);
  95.   }
  96.  
  97.   putc ('\n', file_pointer);
  98.  
  99.  }
  100.  
  101.  
  102.  
  103.  
  104.  tab_string(string)
  105.     char string[];
  106. {
  107.    char temp_string[80];
  108.    int  i;
  109.  
  110.    clear_buffer(temp_string);
  111.    for(i=0; i<8; i++)
  112.       temp_string[i] = ' ';
  113.    for(i=8; i<MAX_NAME_LENGTH; i++)
  114.       temp_string[i] = string[i-8];
  115.    for(i=0; i<MAX_NAME_LENGTH; i++)
  116.       string[i] = temp_string[i];
  117. }  /* ends tab_string  */
  118.